#include "regulationWidget.h"
#include "ui_regulationWidget.h"
#include "EmotionInterface.h"
#include "sys_data_struct.h"

#include <QLabel>
#include <QMessageBox>
#include <iostream>
#include <QProcess>
// #include <QPainter>
// #include <QCloseEvent>

RegulationWidget::RegulationWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RegulationWidget),
    mpvProcess(new QProcess())
{
    ui->setupUi(this);

    QString gifPath = ":/pic/pic/Neutral.gif";
    // QString gifPath = ":/pic/pic/Positive.gif";

    emo_gif = new QMovie(gifPath);
    ui->emo_label->setMovie(emo_gif);
    emo_gif->start();
    ui->emo_label->setScaledContents(true);


    // //定时器连接槽函数
    connect(&delay_time, SIGNAL(timeout()), this, SLOT(changeGIF()));
    // connect(&videoPlay_time, SIGNAL(timeout()), this, SLOT(showVideo()));
    // connect(&delay_show_label, SIGNAL(timeout()), this, SLOT(changeEmoLabel()));


    // delay_time.start(4000);
    // videoPlay_time.start(5000);
    // delay_show_label.start(45000);
    

}

RegulationWidget::~RegulationWidget()
{
    delete emo_gif;
    delete mpvProcess;
    delete ui;
    // std::cout << "~RegulationWidget()" << std::endl;
}

void RegulationWidget::changeGIF(){
    ui->emoWord_label->setText("负性");
    ui->regWorkingState_label->setText("正在进行视频调控");

    // 切换图片
    emo_gif->stop();
    emo_gif->setFileName(":/pic/pic/Negative.gif");
    emo_gif->start();
    emit showVideo("../AllVideo/3.3.mp4");
    delay_time.stop();
}

void RegulationWidget::happyGIF(){
    ui->emoWord_label->setText("正性");
    ui->regWorkingState_label->setText("请保持");
    // 切换图片
    emo_gif->stop();
    emo_gif->setFileName(":/pic/pic/Positive.gif");
    emo_gif->start();

}


void RegulationWidget::closeEvent(QCloseEvent *event)
{
    // mpvProcess->terminate();
    // mpvProcess->waitForFinished();
    // qDebug() << "video play end.";
    emit widgetClose(WINID::Regulation);
    std::cout << "Regulation Windows is closed!" << std::endl;
}


